#pragma once
#include "gtest/gtest.h"
#include "../../Factory/ElementCalculatorFactory.h"
#include "../MASSiCalculator.h"

using SG::Algebra::Matrixd;
using SG::DataStructure::Common::Real;
using namespace SG::FEMSolver::Element;

// ElementCalculatorFactory 是否正确创建 CMASS1 单元计算类
TEST (ElementCalculatorFactoryTest, CreateMASS1Calculator)
{
    ElementCalculatorFactory::Register (ElementTypes::ELETYPE_MASS1, MASSiCalculator::Create);

    // Test data
    const auto calculatorPtr = ElementCalculatorFactory::Create (ElementTypes::ELETYPE_MASS1);
    const auto mass1CalculatorPtr = dynamic_cast<MASSiCalculator*> (calculatorPtr.get ());

    // Check
    ASSERT_TRUE (nullptr != mass1CalculatorPtr);
}


// ElementCalculatorFactory 是否正确创建 CMASS2 单元计算类
TEST (ElementCalculatorFactoryTest, CreateMASS2Calculator)
{
    ElementCalculatorFactory::Register (ElementTypes::ELETYPE_MASS2, MASSiCalculator::Create);  

    // Test data
    const auto calculatorPtr = ElementCalculatorFactory::Create (ElementTypes::ELETYPE_MASS2);
    const auto mass2CalculatorPtr = dynamic_cast<MASSiCalculator*> (calculatorPtr.get ());

    // Check
    ASSERT_TRUE (nullptr != mass2CalculatorPtr);
}


TEST (MASSiCalculator, ComputeStiffness)
{
    // Input data
    const Real m{3.5};

    // Test data
    Matrixd mmTest (2, 2);
    ELAS1Calculator::ComputeStiffness (m, _OUT mmTest);

    // Target data
    const Matrixd mmTarget (2, 2, {3.5, -3.5, -3.5, 3.5});

    // Check
    ASSERT_TRUE (mmTarget == mmTest);
}